<%@ page language="java" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 

"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<%@ include file="/pub/head_bootstrap.inc"%>
<title>${module.moduleName}</title>
</head>
<body class="FrameRightBg">
	<div class="FrameRight">
		<div class="FrameRightInner">
			<!-- location --> 
			<div class="main">
				<div id="standardSearchForm">
					<%@ include file="/WEB-INF/jsp/filter/filter_bootstrap.jsp" %>
					<%@ include file="/WEB-INF/jsp/module/view/new_selector_form.jsp"%>
					<form id="formsearch" method="post">
						<div class="selector-form"></div>
					</form>
				</div>
				<%@ include file="/WEB-INF/jsp/module/view/bootstrap/part/list.jsp" %>
			</div>
		</div>
	</div>
	<%@ include file="/WEB-INF/jsp/demo/base_import.jsp" %>
	<script type="text/javascript">
		var sdlist = null;
		var selector = null;
		$(function () {
			// 渲染选择器
			var defaultParams = [];
			<c:if test="${param.defaultParams!=null}">
		    var params = JSON.parse('${param.defaultParams}'||'{}');
		    for(var key in params){
		    	defaultParams.push({name:key,value:params[key],type:"exact-match"});
		    }
		    </c:if>
		    sdlist = new $.sdModule.list({
		    	element:$(".main"),
				mdId:'${module.moduleId}',
				mdCode:'${module.module}',
				mdName:'${module.moduleName}',
				menuId:'${param.menuId}',
				fields:'${module.moduleDisplay}',
				listJS:'${module.listJs}',
				isSearch:true,
				isFilter:true,
				defaultSearchParam:defaultParams,
				selectorParams:{
			 		selectorData:'${module.selectorData}',
			 		searchCondition:'${module.searchCondition}',
				},
                toolbarParams:{
                    buttons:[{id:"add"},
                        {id:"modify"},
						{id: "delete"},
                        {id:"view",isHide:true},
                        {id:"import",isHide:true},
                        {id:"export",isHide:true}]
                },
                /* 渲染表格 */
                tableParams:{
                	renderColumn:function(column){
                		if(column.type=='attach'){
                			column.formatter=function (value, row, index) {
                				if(row.attachName!=null){
                					return '<a href=\"javascript:downLoad(\'' + row.attachId + '\')\">'+ row.attachName +'</a>'
                				}else{
                					return null;
                				}
    	                    }
                		}
                	},
                	beforeRenderTable:function(tp){
                		if ('${module.module}' == 'layout'){
            		    	tp.columns.push({
            	                    field: 'url',
            	                    title: '地址',
            	                    width: '20%' ,
            	                    formatter: function (value, row, index) {
            	                    	return  '/panel/layout/layoutlist/editPanel.do?id='+row.id;
            	                    }
            	           });
            		    	tp.columns.push({
            	                field: 'operation',
            	                title: '操作',
            	                width: '20%',
            	                formatter: function (value, row, index) {
            	                	var operation = [];
            	                    operation.push('<a class="edit-panel" href="javascript:void(0);" row-id="'+ row.id +'" row-page_id="'+row.pageId+'">编辑</a> ');
            	                    operation.push('<a class="view-panel" href="javascript:void(0);" row-id="'+ row.id +'" row-page_id="'+row.pageId+'">预览</a> ');
            	                	return operation.length > 0 ? operation.join('') : '-';
            	                }
            	            });
            	      	 }
                	}
                }
			});
		    selector = sdlist.getSelector();
		});
		
		function FF_Reload(){
			sdlist.refreshTable();
		}
		
		$(document).on('click', '.edit-panel', function(){
			var id = $(this).attr('row-id');
			var page_id = $(this).attr('row-page_id');
			var url=null;
			if(page_id!='null'){
				$.ajax({
					url: '${baseURL}/panel/page/pagelist/getUrl.do',
					type: 'post',
					async: false,
					data: {id: page_id},
					success:function(data){
						if (data.indexOf('?') == -1)
							data += '?'
						if(data.indexOf('http')==0){
							url=data+'&id='+id;
						}else{
							url="${baseURL}/"+data+'&id='+id;
						}
					}
				})
				parent.f_addTab("editPanel", '画布', url);
			}else{
				parent.f_addTab("editPanel", '可视化面板', '${baseURL}/panel/layout/layoutlist/editPanel.do?id=' + id);
			}
		});
		$(document).on('click', '.view-panel', function(){
			var id = $(this).attr('row-id');
			var page_id = $(this).attr('row-page_id');
			console.log(page_id);
			var url=null;
			if(page_id!='null'){
				$.ajax({
					url: '${baseURL}/panel/page/pagelist/getUrl.do',
					type: 'post',
					async: false,
					data: {id: page_id},
					success:function(data){
						if (data.indexOf('?') == -1)
							data += '?'
						if(data.indexOf('http')==0){
							url=data+'&id='+id+'&isEdit=false';
						}else{
							url="${baseURL}/"+data+'&id='+id+'&isEdit=false';
						}
					}
				})
				parent.f_addTab("editPanel", '画布', url);
			}else{
				parent.f_addTab("editPanel", '可视化面板', '${baseURL}/panel/layout/layoutlist/editPanel.do?id=' + id  + '&isEdit=false');
			}
		});
	</script>
</body>
</html>